package com.ds.robot.assistant.controller;

import com.google.common.cache.LoadingCache;
import com.ds.robot.assistant.common.R;
import com.ds.robot.assistant.job.YunXiaoBugTipJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/bug")
@Slf4j
public class BugController {

    @Autowired
    private YunXiaoBugTipJob yunXiaoBugTipJob;

    @Resource
    private LoadingCache<String, String> userCache;

    @RequestMapping("/query/today")
    public R queryTodayBug() {
        yunXiaoBugTipJob.sendBugReport(false);
        return R.ok("请在企信群中查看缺陷统计报告");
    }

    @RequestMapping("/query/today/prod")
    public R queryTodayProdBug() {
        yunXiaoBugTipJob.sendBugReport(true);
        return R.ok("请在企信群中查看缺陷统计报告");
    }

    @GetMapping("/getCache")
    public Map<String, String> getAllCacheContent() {
        try {
            return userCache.asMap();
        } catch (Exception e) {
            throw new RuntimeException("查询缓存异常", e);
        }
    }

}
